﻿function selectmap(contextPath, callback,ck,more,closedlg){
	var maps = [];
	var dlg = $('#dlg-selectmap');
	if (!dlg.length){
		dlg = $('<div id="dlg-selectmap">' +
				'<div id="dlg-selectmap-layout" fit="true">' +
				'<div region="north" border="false" style="height:32px;padding:5px;">' +
				'已选择区域：<input id="dlg-selectmap-names" readonly="true" style="border:1px solid #ccc;width:400px;">' +
				'&nbsp;<a href="javascript:void(0);"  onclick="selectmap.clear()">清空</a>' +
				'</div>' +
				'<div region="center" style="overflow:hidden">' +
'<img border="0" usemap="#Map" src="'+contextPath+'css/images/map.jpg" />    '+
'<map name="Map" id="Map">                                                                                                  '+
  '<area shape="poly" coords="4,3,176,3,121,218,70,165,4,139" href="javascript:selectmap.select(1,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="1区" />                                               '+
  '<area shape="poly" coords="187,3,148,166,265,183,319,76,349,31,336,4" href="javascript:selectmap.select(2,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="2区" />                                    '+
  '<area shape="poly" coords="351,5,365,34,342,48,314,100,287,161,279,184,319,197,477,21,464,4" href="javascript:selectmap.select(3,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="3区" />             '+
  '<area shape="poly" coords="482,33,350,179,380,207,465,179,461,153,473,141,503,59" href="javascript:selectmap.select(4,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="4区" />                        '+
  '<area shape="poly" coords="510,73,481,144,473,155,477,177,548,155" href="javascript:selectmap.select(5,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="5区" />                                       '+
  '<area shape="poly" coords="482,4,569,179,594,173,683,168,683,5" href="javascript:selectmap.select(6,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="6区" />                                          '+
  '<area shape="poly" coords="4,158,61,172,118,231,121,263,141,311,64,354,16,377,3,414" href="javascript:selectmap.select(7,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="7区" />                     '+
  '<area shape="poly" coords="145,177,130,255,153,311,173,297,228,303,243,227,262,194" href="javascript:selectmap.select(8,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="8区" />                      '+
  '<area shape="poly" coords="273,198,254,232,243,300,323,299,328,205" href="javascript:selectmap.select(9,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="9区" />                                      '+
  '<area shape="poly" coords="346,187,334,202,335,296,412,293,376,218" href="javascript:selectmap.select(10,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="10区" />                                    '+
  '<area shape="poly" coords="386,213,421,290,503,290,504,279,475,188" href="javascript:selectmap.select(11,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="11区" />                                    '+
  '<area shape="poly" coords="483,185,516,277,515,292,586,288,583,250,552,163" href="javascript:selectmap.select(12,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="12区" />                            '+
  '<area shape="poly" coords="574,189,593,251,598,289,683,285,684,179,599,180" href="javascript:selectmap.select(13,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="13区" />                            '+
  '<area shape="poly" coords="9,425,25,386,125,335,142,355,163,357,183,412,69,435,31,438" href="javascript:selectmap.select(14,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="14区" />                 '+
  '<area shape="poly" coords="139,328,151,348,169,349,192,409,247,409,244,376,232,352,231,311,174,306" href="javascript:selectmap.select(15,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="15区" />    '+
  '<area shape="poly" coords="244,306,243,361,254,376,255,408,291,411,329,399,329,307" href="javascript:selectmap.select(16,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="16区" />                    '+
  '<area shape="poly" coords="339,302,339,401,416,397,417,304" href="javascript:selectmap.select(17,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="17区" />                                            '+
  '<area shape="poly" coords="426,303,492,302,502,300,487,393,426,396" href="javascript:selectmap.select(18,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="18区" />                                    '+
  '<area shape="poly" coords="512,300,590,297,593,370,553,421,495,395" href="javascript:selectmap.select(19,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="19区" />                                    '+
  '<area shape="poly" coords="599,296,604,368,570,432,608,448,645,431,677,446,684,441,683,295" href="javascript:selectmap.select(20,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="20区" />            '+

'<area shape="rect" coords="522,430,577,448" href="javascript:selectmap.select(25,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="25" />  '+
'<area shape="rect" coords="403,430,482,448" href="javascript:selectmap.select(24,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="24" />  '+
'<area shape="rect" coords="293,430,372,448" href="javascript:selectmap.select(23,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="23" />  '+
'<area shape="rect" coords="187,430,266,448" href="javascript:selectmap.select(22,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="22" />  '+
'<area shape="rect" coords="87,430,166,448" href="javascript:selectmap.select(21,'+more+','+closedlg+',\'dlg-selectmap\','+callback+');"  alt="21" />   '+





















'</map>'+
				'</div>' +
				'</div>' +
				'</div>').appendTo('body');

			dlg.dialog({
				title:'选择区域',
				width:700,
				height:556,
				modal:true,
				buttons:[{
					text:'确定',
					iconCls:'icon-ok',
					handler:function(){
						dlg.dialog('close');
						if (callback){							
							callback(selectmap.maps);
						}
					}
				},{
					text:'取消',
					iconCls:'icon-cancel',
					handler:function(){dlg.dialog('close');}
				}]
			});
			$('#dlg-selectmap-layout').layout();
			
	$('#dlg-selectmap-names').val(ck);
	var s = ck.split(',');
	selectmap.maps = [];

	for(var i=0; i<s.length; i++){
		selectmap.maps.push(s[i]);
	}		
	
	} else {
		
		dlg.dialog({
			title:'选择区域',
			width:700,
			height:556,
			modal:true,
			buttons:[{
				text:'确定',
				iconCls:'icon-ok',
				handler:function(){
					dlg.dialog('close');
					if (callback){
						callback(selectmap.maps);
					}
				}
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){dlg.dialog('close');}
			}]
		});
		dlg.dialog('open');
		$('#dlg-selectmap-names').val(ck);

		
	}
	var s = ck.split(',');
	selectmap.maps = [];

	for(var i=0; i<s.length; i++){
		selectmap.maps.push(s[i]);
	}
}
selectmap.maps = [];
selectmap.select = function(index,more,closedlg,dlg,callback){

	if (more == false)
	  selectmap.clear();
  var bselect = false;
  
  for(var i=0; i<selectmap.maps.length; i++){
		if (selectmap.maps[i] == index){
			bselect = true;
			break;
			}
	}
  
  if (!bselect){
	  selectmap.maps.push(index);
	  var s = [];
	  for(var i=0; i<selectmap.maps.length; i++){
		  s.push(selectmap.maps[i]);
	  }
	  $('#dlg-selectmap-names').val(s.join(','));
	  if (closedlg){
	    $('#'+dlg).dialog('close');
	    if (callback){
	    	
							callback(selectmap.maps);
						}
	  }
  }
};
selectmap.clear = function(){
	selectmap.maps = [];
	$('#dlg-selectmap-names').val('');
};
